// 售后单详情页
import { handleAfterSaleOrderStatus } from '../../biztools/order';
import { getExpandAfterSaleDetail } from '../../api/order';
import { ORDER_OWNER_TYPE } from '../../../constants/order';
import { AfterSaleOrderDetailMixins } from '../../../behaviors/page';
const { showLoading, hideLoading, } = require('../../../common/env');

Page({
    mixins: [AfterSaleOrderDetailMixins],
    data: {
        orderOwnerType: ORDER_OWNER_TYPE,
        afterSaleOrderDetail: {},
        afterSaleOrderStatusInfo: {},
        spnId: '',
    },

    onLoad: function (options) {
        const { orderNumber, spnId } = options;
        this.setData({
            spnId,
        }, async () => {
            // 获取售后点详情
            await this.refreshAfterOrderDetail(orderNumber);
        });
    },

    // 获取售后单详情
    refreshAfterOrderDetail: async function (orderNumber) {
        showLoading('加载中...');
        const { spnId } = this.data;
        const afterSaleOrderDetail = await getExpandAfterSaleDetail(orderNumber, spnId);
        this.setData({
            afterSaleOrderDetail,
            afterSaleOrderStatusInfo: handleAfterSaleOrderStatus(afterSaleOrderDetail),
        });
        hideLoading();
    },
})